﻿document.write("<script language='javascript' src='~/Content/layer/layer.js'></script>");
/* 
请求Ajax 带返回值
*/
function getAjax(url, postData, callBack) {
    Loading(true);
    $.ajax({
        type: 'post',
        dataType: "text",
        url: url,
        data: postData,
        cache: false,
        async: false,
        success: function (data) {
            callBack(data);
            Loading(false);
        },
        error: function (data) {
            alert("error:" + data + "url:" + url);
            Loading(false);
        }
    });
}

/**
  返回字符串
*/
function ZorPostSimpleData(url, postData, callBack) {
    Loading(true);
    $.ajax({
        type: "POST",
        url: url,                           //"/Service/ListString",
        contentType: "application/json",    //必须有
        dataType: "json",                   //表示返回值类型，不必须
        data: postData,                     //JSON.stringify({ 'foo': 'foovalue', 'bar': 'barvalue' }),  //相当于 //data: "{'str1':'foovalue', 'str2':'barvalue'}",
        success: function (jsonResult) {
            Loading(false);
            callBack(jsonResult);
        },
        error: function (data) {
            Loading(false);
        }
    });
}

/**
   List<string>
 */
function ZorpostListString(url, postData, callBack) {
    $.ajax({
        type: "POST",
        url: url,
        contentType: "application/json",
        dataType: "json",
        data: postData,                     //JSON.stringify({ "BuIds": ["1", "2", "3"] }),
        success: function (jsonResult) {
            callBack(jsonResult);
        }
    });
}


/**
  <T>
 */
function ZorpostEmployees(url, postData, callBack) {
    $.ajax({
        type: "POST",
        url: url,
        contentType: "application/json",
        dataType: "json",
        data: postData,//JSON.stringify({
        //"Employees": 
        //{ "firstName": "Bill", "lastName": "Gates" }
        //}),
        success: function (jsonResult) {
            callBack(jsonResult);
        }
    });
}

/**
  List<T>
 */
function ZorpostListEmployees(url, postData, callBack) {
    $.ajax({
        type: "POST",
        url: "/Service/Employees",
        contentType: "application/json",
        dataType: "json",
        data: postData,//JSON.stringify({
        //"Employees": [
        //{ "firstName": "Bill", "lastName": "Gates" },
        //{ "firstName": "George", "lastName": "Bush" },
        //{ "firstName": "Thomas", "lastName": "Carter" }
        //]

        //}),
        success: function (jsonResult) {
            callBack(jsonResult);
        }
    });
}



/**
数据验证完整性
**/
function CheckDataValid(id) {
    if (!JudgeValidate(id)) {
        return false;
    } else {
        return true;
    }
}

function IsNullOrEmpty(str) {
    var isOK = true;
    if (str == undefined || str == "") {
        isOK = false;
    }
    return isOK;
}

/**
  *时间戳转换为时间
  */
function DataIntToDate(nowdate) {
    var now = new Date(nowdate * 1000);
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours();
    var minute = now.getMinutes();
    var second = now.getSeconds();
    return formatDate((year + "-" + month + "-" + date + "   " + hour + ":" + minute + ":" + second), "yyyy-MM-dd hh:mm:ss");
}

/**
  *时间戳转换为时间(没有时分秒)
  */
function TimeStampToDateTime(nowdate) {
    var now = new Date(nowdate * 1000);
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    return formatDate((year + "-" + month + "-" + date ), "yyyy-MM-dd");
}

/*
 * 弹出窗体
 */
function LayerOpen(yWidth,yHeight,yTitle,yHtml) {

    layer.open({
        type: 1,
        title: yTitle,
        shade: 0.6,
        maxmin: true,
        skin: 'layui-layer-rim',
        area: [yWidth, yHeight], //宽高
        content: yHtml
    })

}



/* 
请求Ajax 带返回值
*/
function getAjax(url, postData, callBack) {
    //Loading(true);
    $.ajax({
        type: 'post',
        dataType: "text",
        url: url,
        data: postData,
        cache: false,
        async: false,
        success: function (data) {
            callBack(data);
            // Loading(false);
        },
        error: function (data) {
            alert("error:" + data + "url:" + url);
            Loading(false);
        }
    });
}


/*
刷新当前页面
*/
function Replace() {
    location.reload();
    return false;
}



/**
当前时间
*/
function CurrentTime() {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute;
}






/*
自动获取页面控件值
*/
function GetWebControls(element) {
    var reVal = "";
    $(element).find('input,select,textarea').each(function (r) {
        var id = $(this).attr('id');
        var value = $(this).val();
        var type = $(this).attr('type');
        switch (type) {
            case "checkbox":
                if ($(this).attr("checked")) {
                    reVal += '"' + id + '"' + ':' + '"1",'
                } else {
                    reVal += '"' + id + '"' + ':' + '"0",'
                }
                break;
            default:
                if (value == "") {
                    value = "";
                }
                reVal += '"' + id + '"' + ':' + '"' + $.trim(value) + '",'
                break;
        }
    });
    reVal = reVal.substr(0, reVal.length - 1);
    return jQuery.parseJSON('{' + reVal + '}');
}

/*
 * 清空 DOM 的值
 */
function ClearWebControls(element) {
    $(element).find('input,select,textarea').each(function (r) {
        var type = $(this).attr('type');
        if (type == "text" || type == "textarea")
            $(this).val("");
        else
            $(this).find("option").eq(0).prop("selected", true)
    })
}




/*
自动给控件赋值
*/
function SetWebControls(data) {
    for (var key in data) {
        var id = $('#' + key);
        var value = $.trim(data[key]).replace("&nbsp;", "");
        var type = id.attr('type');
        switch (type) {
            case "checkbox":
                if (value == 1) {
                    id.attr("checked", 'checked');
                } else {
                    id.removeAttr("checked");
                }
                $('input').customInput();
                break;
            default:
                id.val(value);
                break;
        }
    }
}



/*
自动给控件赋值、对Lable
*/
function SetWebLable(data) {
    for (var key in data) {
        var id = $('#' + key);
        var value = $.trim(data[key]).replace("&nbsp;", "");
        id.text(value);
    }
}

/**
获取选中复选框值
值：1,2,3,4
**/
function CheckboxValue() {
    var reVal = '';
    $('[type=checkbox]').each(function () {
        if ($(this).attr("checked")) {
            reVal += $(this).val() + ",";
        }
    });
    reVal = reVal.substr(0, reVal.length - 1);
    return reVal;
}

/**
获取选中复选框值(数组)
值：1,2,3,4
**/
function CheckboxValueIDs() {
    var chk_value = [];
    $('input[name="chk"]:checked').each(function () {
        chk_value.push($(this).val());
    });
    return chk_value;
}


/*
 * 获取表格单元格值
 */
function getTableCell(CellIndex) {
    var meg = "";
    $('input[name="chk"]:checked').each(function () {
        meg = $(this).parents('tr').find('td').eq(CellIndex).text();
    });
    return meg;
}

/**
获取选中复选框id(数组) 卡片管理获取选中的卡编号
值：1,2,3,4
**/
function CheckboxCardNO() {
    var chk_value = [];
    $('input[name="chk"]:checked').each(function () {
        chk_value.push($(this).attr("id")); //获取选中的卡编号
    });
    return chk_value;
}